queryManagement()
function queryManagement() {
    var areaLists=[]
    for(var i=0;$("input:checkbox[name='saleArea']:checked").length>i;i++) {
        areaLists.push($("input:checkbox[name='saleArea']:checked")[i].value)
    }
    $.ajax({
        url: root.appversioncontrol.listWheelPictureBack,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "pageNum":1,
            "pageSize":30,
            "platform": $("#platform").val().trim(),//平台
            "picTitle":$("#picTitle").val().trim(),
            "picStatus":$("#picStatus").val().trim(),
            "effectStartTime":$("#timemin").val().trim(),
            "effectEndTime":$("#timemax").val().trim(),
            "areaList":areaLists,
            "afterFrom":20
        }),
        success: function (data) {
            couponlist(data.data, 0);
            $('.M-box3').pagination({
                pageCount: data.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.appversioncontrol.listWheelPictureBack,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":30,
                            "platform": $("#platform").val().trim(),//平台
                            "picTitle":$("#picTitle").val().trim(),
                            "picStatus":$("#picStatus").val().trim(),
                            "effectStartTime":$("#timemin").val().trim(),
                            "effectEndTime":$("#timemax").val().trim(),
                            "areaList":areaLists,
                            "afterFrom":20

                        }),
                        success: function (result) {
                            couponlist(result.data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
function couponlist(data, index){
    dataSource.splice(0,dataSource.length);//清空数组
        if(data!=null&& data!=""){
            var datashu =data.startIndex+1;
            $.each(data.data, function (i, field) {
                var datashus = datashu++
                var rowData = new Array();
                rowData.push(field.picTitle);
                rowData.push(field.areaList);
                rowData.push(field.platform);
                rowData.push(field.startTime);
                rowData.push(field.picStatus);
                rowData.push(field.createTime);
                rowData.push(field.userName);
                rowData.push(field.picId);
                rowData.push(datashus)
                rowData.push(field.endTime);
                dataSource.push(rowData);

            });

        }
    initDataTable(dataSource);

    function initDataTable(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable

        $("#datatable").DataTable({
            "order": [[ 0, "desc" ]],
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu":[10,20,30],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        console.log(row[8])
                        var val = row[8]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var abnormalType = "";
                        var abnormalTypeArr = [];
                        var names=''
                        var region=JSON.parse(sessionStorage.getItem("warehouses"))
                        $.each(row[1],function(n,d){
                        $.each(region.data,function(k,s){

                                if(d==s.warehouseCode){
                                    names=s.warehouseName
                                    names=names.match(/(\S*)仓/)[1];

                                }

                                })

                            abnormalTypeArr.push(names);
                        })

                        for (var j = 0; j < abnormalTypeArr.length; j++) {
                            if (j < abnormalTypeArr.length - 1) {
                                abnormalType += abnormalTypeArr[j] + "/";
                            } else {
                                abnormalType += abnormalTypeArr[j] + "";
                            }
                        }
                        return abnormalType;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val=""
                        if (row[2] == 0) {
                            val = '签约/普通'
                        }else if(row[2] ==10){
                            val = '签约'
                        }else if(row[2] ==20){
                            val = '普通'
                        }
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ''+row[3]+'~'+row[9]+''
                        return val;
                    },
                    "targets":4
                },
                {
                    "render": function(data,type,row,meta){
                        var val=""
                        if (row[4]==10){
                            val='生效'
                        }else if (row[4]==20){
                            val='未生效'
                        }else if (row[4]==30){
                            val='已失效'
                        }
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var date = row[5];
                        var split = date.split(" ");
                        val = split[0] + '<br/>' + split[1];
                        return val;
                    },
                    "targets":6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[6]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 7
                },


                {
                    "render": function (data, type, row, meta) {

                        var val ='<a class="" onclick="jumpPage(\'轮播图编辑\',\'moban.html?page=2\','+row[2]+','+row[7]+')">编辑</a>&nbsp;&nbsp;<a class="" onclick="deleteData('+row[7]+')">删除</a>'

                        return val;
                    },
                    "targets":8
                },


            ]
        });
        //权限控制函数
        power()

    };
}


/*跳转详情*/
function jumpPage(title,url,data,editpicId){
    sessionStorage.setItem("platforms",data);
    sessionStorage.setItem("editpicIds",editpicId)
    sessionStorage.setItem("listReturn",20)
    var index = layer.open({
        type: 2,
        title: title,
        content: url,
        /* 关闭弹出框的回调函数*/
        end:function () {
            sessionStorage.removeItem("listReturn");
            sessionStorage.removeItem("platforms");
        }
    });
    layer.full(index);
}
//删除
function deleteData(id) {
    var curInd = layer.confirm(
        '<span>确定删除吗？</span>'+'<br/>', {title:'提示',btn: ['确定', '取消']}, function(index){
            $.ajax({
                url:root.appversioncontrol.deleteWheelPicture,
                cache: false,  //禁用缓存
                type: "POST",
                dataType: 'json',
                data: {
                    "picId":id,
                },
                success: function (data) {
                    if(data.errorCode==0){
                        $.Huimodalalert('删除成功',2000);
                        queryManagement()

                    }else {
                        $.Huimodalalert(data.msg,2000);

                    }
                },
                error: function () {
                    $.Huimodalalert('失败！',2000);
                }
            })
            layer.close(curInd);

        },function(){
            layer.close(curInd);

        });
}
//返回
function returns() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
    sessionStorage.removeItem("listReturn");
    sessionStorage.removeItem("platforms");
}
//限制字符
var len
var Preser
var common=20//要限制输入的字数
function checkMaxIut(me) {
    var text=$(me).val()
    strlen(text)
    if(len>common){
        $(me).val(Preser)
    }else {
        Preser=$(me).val()
    }
}
function strlen(str){
    len = 0;
    for (var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            len++;
        } else {
            len+=2;
        }
    }
    return len;
}